import java.util.Arrays;

public class ShellSort {
    public static void main(String[] args) {
        int[] array = {105,95,65,85,75,15,5};
        shellSort(array);
        System.out.println(Arrays.toString(array));

    }

    private static void shellSort(int[] array) {
        int len = array.length;
//        int gap = len/2;
        while (len > 1 ){
            len /= 2;
            shellSort(array,len);
//            gap = gap/2;
        }
    }

    private static void shellSort(int[] array, int gap) {
        for (int i = gap; i < array.length ; i++) {
            int tmp = array[i];
            int j = i-gap;
            for (; j >= 0 ; j-=gap) {
                if(array[j] > tmp){
                    array[j+gap] = array[j];
                }else {
                    break;
                }
            }
            array[j+gap] = tmp;
        }
    }
}
